# 导入进程模块
import multiprocessing
import time
import os


# 编写代码
def coding():
    # 获取当前进程的编号
    print("coding:", os.getpid())
    # 获取当前进程
    print("coding:", multiprocessing.current_process())
    # 获取⽗进程的编号
    print("coding⽗进程编号:", os.getppid())
    for i in range(3):
        print("coding...")
        time.sleep(0.2)
        # 扩展:根据进程编号杀死指定进程
        os.kill(os.getpid(), 9)

# 听音乐
def music():
    for i in range(3):
        print("music...")
        time.sleep(0.2)


if __name__ == '__main__':
    # 获取当前进程的编号
    print("main:", os.getpid())
    # 获取当前进程
    print("main:", multiprocessing.current_process())
    # coding()
    # music()
    # 通过进程类创建进程对象
    coding_process = multiprocessing.Process(target=coding)
    # 通过进程类创建进程对象
    music_process = multiprocessing.Process(target=music)
    # 启动进程
    music_process.start()
    coding_process.start()

"""
小结：
获取当前进程编号：os.getpid()
获取当前⽗进程编号：os.getppid()
"""

